﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace NBusiness.Data
{
    public abstract class CommandBase : IDisposable
    {
        EventWaitHandle _wait = new EventWaitHandle(false, EventResetMode.ManualReset);

        protected internal virtual void Initialize() { }
        public virtual void Dispose() { }

        protected internal abstract void Run();

        public void Join() 
        {
            _wait.WaitOne();
        }

        public event EventHandler Completed;
        protected void OnCompleted()
        {
            _wait.Set();
            if (Completed != null)
                Completed(this, EventArgs.Empty);
        }
    }
}
